Parse and output TODOs and FIXMEs from comments in your files
Easily extract, collect and report TODOs and FIXMEs in your code. This project uses regex in order
to extract your todos from comments.
TODO: add some info
- Spaces are optional.
- Colon is optional.
- Must be in a comment (line or block) in its' own line (
some code(); //TODO: do something
is not supported). - Can be prefixed with a @ (i.e @TODO).
- Spaces are trimmed around comment text.
- Supported default types are
TODO
and FIXME
- case insensitive. - Additional types can be added (using
tags
in cli and customTags
in leasot.parse
)
Supported languages:
Filetype | Extension | Notes |
---|
C# | .cs | Supports // and /* */ comments. |
C++/C | .cpp .c .h | Supports // and /* */ comments. |
Coffee-React | .cjsx | Supports # comments. |
Coffeescript | .coffee | Supports # comments. |
CSS | .css | Supports /* */ comments. |
Erlang | .erl | Supports % comments. |
Go | .go | Supports // and /* */ comments. |
Handlebars | .hbs .handlebars | Supports {{! }} and {{!-- --}} |
Haskell | .hs | Supports -- |
Hogan | .hgn .hogan | Supports {{! }} and {{!-- --}} |
HTML | .html .htm | Supports <!-- --> |
EJS | .ejs | Supports <!-- --> and <%# %> |
Jade | .jade | Supports // and //- comments. |
Javascript | .js | Supports // and /* */ comments |
Jsx | .jsx | Supports // and /* */ comments. |
Less | .less | Supports // and /* */ comments. |
Mustache | .mustache | Supports {{! }} and {{!-- --}} |
Perl | .pl , .pm | Supports # comments. |
PHP | .php | Supports // and /* */ comments. |
Python | .py | Supports """ and # comments. |
Ruby | .rb | Supports # comments. |
Sass | .sass .scss | Supports // and /* */ comments. |
Shell | .sh .zsh .bash | Supports # comments. |
Stylus | .styl | Supports // and /* */ comments. |
Twig | .twig | Supports {# #} and <!-- --> |
Typescript | .ts | Supports // and /* */ comments. |
Javascript is the default parser.
PRs for additional filetypes is most welcomed!!
Usage
Command Line
Installation
$ npm install --global leasot
Examples
❯ leasot --help
Usage: leasot [options] <file ...>
Parse and output TODOs and FIXMEs from comments in your files
Options:
-h, --help output usage information
-V, --version output the version number
-r, --reporter [reporter] use reporter (table|json|xml|markdown|raw) (default: table)
-t, --filetype [filetype] force the filetype to parse. Useful for streams (default: .js)
-T, --tags <tags> add additional comment types to find (alongside todo & fixme)
-S, --skip-unsupported skip unsupported filetypes
Examples:
$ leasot index.js
$ leasot **/*.php
$ leasot app/**/*.js test.rb
$ leasot --reporter json index.js
$ leasot --tags review index.js
$ leasot --reporter markdown app/**/*.py > TODO.md
$ cat index.coffee | leasot --filetype .coffee
Programmatic
Installation
$ npm install --save-dev leasot
Examples
var fs = require('fs');
var leasot = require('leasot');
var contents = fs.readFileSync('./contents.js', 'utf8');
var filetype = path.extname('./contents.js');
var file = 'contents.js';
var todos = leasot.parse(filetype, contents, file);
var output = leasot.reporter(todos, {
reporter: 'json',
spacing: 2
});
console.log(output);
Build Time
API
var leasot = require('leasot');
leasot
exposes the following API:
.isExtSupported(extension)
Check whether extension is supported by parser.
Specify an extension including the prefixing dot, for example:
leasot.isExtSupported('.js'); //-> true
Returns: Boolean
.parse(extension, contents, filename, customTags)
Parse the contents, using the provided extension
. filename
will be attached
to the return object, so it is recommended to use it if you know it.
extension
is the extension to parse as, including a prefixing dot.
contents
is a string containing the contents to parse.
filename
is an optional string.
customTags
is an optional array with additional tags (comment types) to search for (alongside todo & fixme).
Returns: Array
of comments.
[{
file: 'parsedFile.js',
text: 'comment text',
kind: 'TODO',
line: 8
}]
Use the specified reporter to report the comments.
comments
is the array of comments received from leasot.parse()
.
config
is an object that will also be passed to the reporter itself (allowing custom options for each reporter).
It may also contain the specified reporter:
config.reporter
Can be a string indicating the built-in reporter to use,
or an external library used as a reporter.
Could also be a custom function (comments, config)
Type: String|Function
Required: false
Default: raw
Built-in Reporters
Each reporter might contain config params that are useful only for that reporter:
Markdown
Returns a markdown version of the todos.
Options
newLine
How to separate lines in the output file. Defaults to your OS's default line separator.
Type: String
Default: Your system default line feed
padding
How many newLine
s should separate between comment type blocks.
Type: Number
Default: 2
Minimum: 0
Control the output of a header for each comment kind (i.e todo, fixme).
Type: Function
Default:
transformHeader: function (kind) {
return ['### ' + kind + 's',
'| Filename | line # | ' + kind,
'|:------|:------:|:------'
];
}
kind: will be be passed as the comment kind (todo/fixme).
Returns: String[]|String
You are expected to return either an Array of strings
or just a string
. If you return an array - each item will be separated by a newline in the output.
Control the output for each comment.
Type: Function
Default:
transformComment: function (file, line, text, kind) {
return ['| ' + file + ' | ' + line + ' | ' + text];
},
file: filename the comment was in.
line: line of comment.
text: comment text
kind: will be be passed as the comment kind (todo/fixme).
Returns: String[]|String
You are expected to return either an Array of strings
or just a string
. If you return an array - each item will be separated by a newline in the output.
Table
Returns a pretty formatted table of the todos.
Raw
Just returns the raw javascript todos
JSON
Return a JSON valid representation of the todos.
Options
spacing
Type: Number
Default: 2
XML
Return an unformatted XML valid representation of the todos.
Parsed using json2xml
Options
Whether to include xml header
Type: Boolean
Default: true
attributes_key
See https://github.com/estheban/node-json2xml#options--behaviour
Type: Boolean
Default: undefined
License
MIT ©Gilad Peleg